/*
 * VetCliniView.java
 */

package vetclini;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.GregorianCalendar;
import veterinario.*;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFrame;
import veterinario.Animal;

/**
 * The application's main frame.
 * @author 2011101993 - Hugo Amaro
 * @author 2006130415 - Jorge Martins Alves
 */
public class VetCliniView extends FrameView {

    private Clinica clinica;
    private Cliente editCliente;


    public VetCliniView(SingleFrameApplication app) {
        super(app);

        initComponents();

        this.clinica = new Clinica();

        this.getFrame().addWindowListener(new MyWindowListener(this.clinica));

        updateLists();
    }

    final public void updateLists(){
        listaCliente.setListData(this.clinica.getInlineDescriptionClientes());
        listaMedico.setListData(this.clinica.getInlineDescriptionMedicos());
        listaAnimal.setListData(this.clinica.getInlineDescriptionAnimais());
        listaInternamento.setListData(this.clinica.getInlineDescriptionInternamentos());
        listaConsulta.setListData(this.clinica.getInlineDescriptionConsultas());
        filtroAnimaisCliente.removeAllItems();
        filtroAnimaisCliente.addItem("Qualquer Cliente");
        for(int i=0; i<this.clinica.clientes().size(); i++)
            filtroAnimaisCliente.addItem(this.clinica.clientes().get(i).getNome());

        totalConsultas.setText("€ "+clinica.getConsultasTotal(null, null));
        totalInternamentos.setText("€ "+clinica.getInternamentosTotal(null, null));

        setMedicoValorMais();
        cancelShowMedico();

        nomeCliente.setEnabled(false);
        listaAnimaisCliente.setEnabled(false);
        novoAnimalCliente.setEnabled(false);
        apagarAnimalCliente.setEnabled(false);
        guardaCliente.setEnabled(false);
    }

    public Clinica getClinica(){
        return this.clinica;
    }

    public void editClient(int idx){
        nomeCliente.setEnabled(true);
        listaAnimaisCliente.setEnabled(true);
        novoAnimalCliente.setEnabled(true);
        apagarAnimalCliente.setEnabled(true);
        guardaCliente.setEnabled(true);
        editCliente = this.clinica.clientes().get(idx);
        nomeCliente.setText(editCliente.getNome());
        updateClientAnimalList();
    }
    
    public void updateClientAnimalList(){
        String[] listaNova = new String[editCliente.getAnimais().size()];
        for(int i=0; i<editCliente.getAnimais().size(); i++){
            if(editCliente.getAnimais().get(i).getClass()==Criacao.class)
                listaNova[i] = ((Criacao)editCliente.getAnimais().get(i)).listaString();
            else
                listaNova[i] = ((Estimacao)editCliente.getAnimais().get(i)).listaString();
        }
        listaAnimaisCliente.setListData(listaNova);
    }

    public void cancelEditClient(){
        editCliente = null;
        nomeCliente.setText("");
        String[] listaNova = new String[0];
        listaAnimaisCliente.setListData(listaNova);
        nomeCliente.setEnabled(false);
        listaAnimaisCliente.setEnabled(false);
        novoAnimalCliente.setEnabled(false);
        apagarAnimalCliente.setEnabled(false);
        guardaCliente.setEnabled(false);
    }

    public void addAnimalCliente(Animal novoAnimal){
        novoAnimal.setId(clinica.newAnimal());
        editCliente.addAnimal(novoAnimal);
        updateClientAnimalList();
    }
    
    public void subAnimalCliente(int inde){
        editCliente.getAnimais().remove(inde);
        updateClientAnimalList();
    }

    public void setMedicoValorMais(){
        if(clinica.medicos().size()>0&&clinica.eventos().size()>0){
            int index = 0;
            float valor = 0;
            for(int i=0; i<clinica.medicos().size(); i++){
                float tempVal = clinica.getTotalMedico(clinica.medicos().get(i));
                if(tempVal>valor){
                    valor = tempVal;
                    index = i;
                }
            }
            medicoValorMais.setText("Nome: "+clinica.medicos().get(index).getNome()+" Valor: € "+valor);
        }
    }

    public void showMedico(int idx){
        verMedicoNome.setText(clinica.medicos().get(idx).getNome());
        verMedicoMedia.setText(""+clinica.mediaConsultas(clinica.medicos().get(idx)));
        verMedicoPadrao.setText(""+clinica.desvioPadraoConsultas(clinica.medicos().get(idx)));
    }

    public void cancelShowMedico(){
        verMedicoNome.setText("");
        verMedicoMedia.setText("");
        verMedicoPadrao.setText("");
    }

    

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = VetCliniApp.getApplication().getMainFrame();
            aboutBox = new VetCliniAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        VetCliniApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaCliente = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        apagarCliente = new javax.swing.JButton();
        novoCliente = new javax.swing.JButton();
        viewClientePanel = new javax.swing.JPanel();
        guardaCliente = new javax.swing.JButton();
        apagarAnimalCliente = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        listaAnimaisCliente = new javax.swing.JList();
        novoAnimalCliente = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        nomeCliente = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        novoMedico = new javax.swing.JButton();
        apagarMedico = new javax.swing.JButton();
        viewMedicoPanel = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        verMedicoNome = new javax.swing.JLabel();
        verMedicoMedia = new javax.swing.JLabel();
        verMedicoPadrao = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaMedico = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        medicoValorMais = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        viewAnimalPanel = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listaAnimal = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tipoFiltroAnimais = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        filtroAnimaisCliente = new javax.swing.JComboBox();
        textoFiltro = new javax.swing.JTextField();
        butaoFiltrarAnimais = new javax.swing.JButton();
        butaoCancelarFiltroAnimais = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        novoInternamento = new javax.swing.JButton();
        apagarInternamento = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        listaInternamento = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        filtroInternamentoInicioDia = new javax.swing.JTextField();
        filtroInternamentoInicioMes = new javax.swing.JTextField();
        filtroInternamentoInicioAno = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        filtroInternamentoFimDia = new javax.swing.JTextField();
        filtroInternamentoFimMes = new javax.swing.JTextField();
        filtroInternamentoFimAno = new javax.swing.JTextField();
        filtroInternamentoFiltrar = new javax.swing.JButton();
        filtroInternamentoCancelar = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        totalInternamentos = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        novoConsulta = new javax.swing.JButton();
        apagarConsulta = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        listaConsulta = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        filtroConsultaInicioDia = new javax.swing.JTextField();
        filtroConsultaInicioMes = new javax.swing.JTextField();
        filtroConsultaInicioAno = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        filtroConsultaFimDia = new javax.swing.JTextField();
        filtroConsultaFimMes = new javax.swing.JTextField();
        filtroConsultaFimAno = new javax.swing.JTextField();
        filtroConsultaFiltrar = new javax.swing.JButton();
        filtroConsultaCancelar = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        totalConsultas = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        jTabbedPane1 = new javax.swing.JTabbedPane();

        mainPanel.setName("mainPanel"); // NOI18N

        jTabbedPane2.setName("jTabbedPane2"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        listaCliente.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaCliente.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaCliente.setName("listaCliente"); // NOI18N
        listaCliente.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaClienteValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listaCliente);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(vetclini.VetCliniApp.class).getContext().getResourceMap(VetCliniView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(vetclini.VetCliniApp.class).getContext().getActionMap(VetCliniView.class, this);
        apagarCliente.setAction(actionMap.get("clickedRemoverCliente")); // NOI18N
        apagarCliente.setFont(resourceMap.getFont("apagarCliente.font")); // NOI18N
        apagarCliente.setForeground(resourceMap.getColor("apagarCliente.foreground")); // NOI18N
        apagarCliente.setText(resourceMap.getString("apagarCliente.text")); // NOI18N
        apagarCliente.setName("apagarCliente"); // NOI18N

        novoCliente.setAction(actionMap.get("clickedNovoCliente")); // NOI18N
        novoCliente.setFont(resourceMap.getFont("novoCliente.font")); // NOI18N
        novoCliente.setForeground(resourceMap.getColor("novoCliente.foreground")); // NOI18N
        novoCliente.setText(resourceMap.getString("novoCliente.text")); // NOI18N
        novoCliente.setName("novoCliente"); // NOI18N

        viewClientePanel.setName("viewClientPanel"); // NOI18N

        guardaCliente.setAction(actionMap.get("clickedGuardarCliente")); // NOI18N
        guardaCliente.setText(resourceMap.getString("guardaCliente.text")); // NOI18N
        guardaCliente.setName("guardaCliente"); // NOI18N

        apagarAnimalCliente.setAction(actionMap.get("clickedRemoverAnimalCliente")); // NOI18N
        apagarAnimalCliente.setFont(resourceMap.getFont("apagarAnimalCliente.font")); // NOI18N
        apagarAnimalCliente.setForeground(resourceMap.getColor("apagarAnimalCliente.foreground")); // NOI18N
        apagarAnimalCliente.setText(resourceMap.getString("apagarAnimalCliente.text")); // NOI18N
        apagarAnimalCliente.setName("apagarAnimalCliente"); // NOI18N

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        listaAnimaisCliente.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaAnimaisCliente.setName("listaAnimaisCliente"); // NOI18N
        jScrollPane6.setViewportView(listaAnimaisCliente);

        novoAnimalCliente.setAction(actionMap.get("clickedNovoAnimalCliente")); // NOI18N
        novoAnimalCliente.setFont(resourceMap.getFont("novoAnimalCliente.font")); // NOI18N
        novoAnimalCliente.setForeground(resourceMap.getColor("novoAnimalCliente.foreground")); // NOI18N
        novoAnimalCliente.setText(resourceMap.getString("novoAnimalCliente.text")); // NOI18N
        novoAnimalCliente.setName("novoAnimalCliente"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        nomeCliente.setName("nomeCliente"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        javax.swing.GroupLayout viewClientePanelLayout = new javax.swing.GroupLayout(viewClientePanel);
        viewClientePanel.setLayout(viewClientePanelLayout);
        viewClientePanelLayout.setHorizontalGroup(
            viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewClientePanelLayout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addGroup(viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(viewClientePanelLayout.createSequentialGroup()
                        .addComponent(novoAnimalCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(apagarAnimalCliente))
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(98, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, viewClientePanelLayout.createSequentialGroup()
                .addContainerGap(201, Short.MAX_VALUE)
                .addComponent(guardaCliente)
                .addGap(165, 165, 165))
            .addGroup(viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(viewClientePanelLayout.createSequentialGroup()
                    .addGap(73, 73, 73)
                    .addComponent(jLabel7)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(nomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(100, Short.MAX_VALUE)))
        );
        viewClientePanelLayout.setVerticalGroup(
            viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewClientePanelLayout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoAnimalCliente)
                    .addComponent(apagarAnimalCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(guardaCliente)
                .addContainerGap(32, Short.MAX_VALUE))
            .addGroup(viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(viewClientePanelLayout.createSequentialGroup()
                    .addGap(46, 46, 46)
                    .addGroup(viewClientePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(nomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(211, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38)
                        .addComponent(viewClientePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(novoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(apagarCliente))
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(viewClientePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoCliente)
                    .addComponent(apagarCliente))
                .addContainerGap(354, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        novoMedico.setAction(actionMap.get("clickedNovoMedico")); // NOI18N
        novoMedico.setFont(resourceMap.getFont("novoMedico.font")); // NOI18N
        novoMedico.setForeground(resourceMap.getColor("novoMedico.foreground")); // NOI18N
        novoMedico.setText(resourceMap.getString("novoMedico.text")); // NOI18N
        novoMedico.setName("novoMedico"); // NOI18N

        apagarMedico.setAction(actionMap.get("clickedRemoverMedico")); // NOI18N
        apagarMedico.setFont(resourceMap.getFont("apagarMedico.font")); // NOI18N
        apagarMedico.setForeground(resourceMap.getColor("apagarMedico.foreground")); // NOI18N
        apagarMedico.setText(resourceMap.getString("apagarMedico.text")); // NOI18N
        apagarMedico.setName("apagarMedico"); // NOI18N

        viewMedicoPanel.setName("viewMedicoPanel"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        verMedicoNome.setText(resourceMap.getString("verMedicoNome.text")); // NOI18N
        verMedicoNome.setName("verMedicoNome"); // NOI18N

        verMedicoMedia.setText(resourceMap.getString("verMedicoMedia.text")); // NOI18N
        verMedicoMedia.setName("verMedicoMedia"); // NOI18N

        verMedicoPadrao.setText(resourceMap.getString("verMedicoPadrao.text")); // NOI18N
        verMedicoPadrao.setName("verMedicoPadrao"); // NOI18N

        javax.swing.GroupLayout viewMedicoPanelLayout = new javax.swing.GroupLayout(viewMedicoPanel);
        viewMedicoPanel.setLayout(viewMedicoPanelLayout);
        viewMedicoPanelLayout.setHorizontalGroup(
            viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewMedicoPanelLayout.createSequentialGroup()
                .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(viewMedicoPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel22)
                        .addGap(6, 6, 6)
                        .addComponent(verMedicoPadrao))
                    .addGroup(viewMedicoPanelLayout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel20)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(verMedicoMedia)
                            .addComponent(verMedicoNome))))
                .addContainerGap(341, Short.MAX_VALUE))
        );
        viewMedicoPanelLayout.setVerticalGroup(
            viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewMedicoPanelLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(verMedicoNome))
                .addGap(18, 18, 18)
                .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(verMedicoMedia))
                .addGap(18, 18, 18)
                .addGroup(viewMedicoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(verMedicoPadrao))
                .addContainerGap(183, Short.MAX_VALUE))
        );

        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setName("jScrollPane2"); // NOI18N

        listaMedico.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaMedico.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaMedico.setName("listaMedico"); // NOI18N
        listaMedico.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaMedicoValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listaMedico);

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        medicoValorMais.setText(resourceMap.getString("medicoValorMais.text")); // NOI18N
        medicoValorMais.setName("medicoValorMais"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(viewMedicoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(novoMedico, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(apagarMedico)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(medicoValorMais)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(viewMedicoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoMedico)
                    .addComponent(apagarMedico)
                    .addComponent(jLabel19)
                    .addComponent(medicoValorMais))
                .addContainerGap(346, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        viewAnimalPanel.setName("viewAnimalPanel"); // NOI18N

        javax.swing.GroupLayout viewAnimalPanelLayout = new javax.swing.GroupLayout(viewAnimalPanel);
        viewAnimalPanel.setLayout(viewAnimalPanelLayout);
        viewAnimalPanelLayout.setHorizontalGroup(
            viewAnimalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 313, Short.MAX_VALUE)
        );
        viewAnimalPanelLayout.setVerticalGroup(
            viewAnimalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 285, Short.MAX_VALUE)
        );

        jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane3.setName("jScrollPane3"); // NOI18N

        listaAnimal.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaAnimal.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaAnimal.setName("listaAnimal"); // NOI18N
        jScrollPane3.setViewportView(listaAnimal);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        tipoFiltroAnimais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Raça", "Nome", "Origem" }));
        tipoFiltroAnimais.setName("tipoFiltroAnimais"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        filtroAnimaisCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        filtroAnimaisCliente.setName("filtroAnimaisCliente"); // NOI18N

        textoFiltro.setText(resourceMap.getString("textoFiltro.text")); // NOI18N
        textoFiltro.setName("textoFiltro"); // NOI18N

        butaoFiltrarAnimais.setAction(actionMap.get("clickedButaoFiltrarAnimais")); // NOI18N
        butaoFiltrarAnimais.setText(resourceMap.getString("butaoFiltrarAnimais.text")); // NOI18N
        butaoFiltrarAnimais.setName("butaoFiltrarAnimais"); // NOI18N

        butaoCancelarFiltroAnimais.setAction(actionMap.get("clickedButaoCancelarFiltroAnimais")); // NOI18N
        butaoCancelarFiltroAnimais.setText(resourceMap.getString("butaoCancelarFiltroAnimais.text")); // NOI18N
        butaoCancelarFiltroAnimais.setName("butaoCancelarFiltroAnimais"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                                    .addGap(26, 26, 26)
                                    .addComponent(viewAnimalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel8))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tipoFiltroAnimais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textoFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(filtroAnimaisCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butaoFiltrarAnimais)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butaoCancelarFiltroAnimais)))
                .addGap(63, 63, 63))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(tipoFiltroAnimais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(filtroAnimaisCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(butaoFiltrarAnimais)
                    .addComponent(butaoCancelarFiltroAnimais))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(viewAnimalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(360, 360, 360))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        novoInternamento.setAction(actionMap.get("clickedNovoInternamento")); // NOI18N
        novoInternamento.setFont(resourceMap.getFont("novoInternamento.font")); // NOI18N
        novoInternamento.setForeground(resourceMap.getColor("novoInternamento.foreground")); // NOI18N
        novoInternamento.setText(resourceMap.getString("novoInternamento.text")); // NOI18N
        novoInternamento.setName("novoInternamento"); // NOI18N

        apagarInternamento.setAction(actionMap.get("clickedRemoverInternamento")); // NOI18N
        apagarInternamento.setFont(resourceMap.getFont("apagarInternamento.font")); // NOI18N
        apagarInternamento.setForeground(resourceMap.getColor("apagarInternamento.foreground")); // NOI18N
        apagarInternamento.setText(resourceMap.getString("apagarInternamento.text")); // NOI18N
        apagarInternamento.setName("apagarInternamento"); // NOI18N

        jScrollPane4.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane4.setName("jScrollPane4"); // NOI18N

        listaInternamento.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaInternamento.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaInternamento.setName("listaInternamento"); // NOI18N
        jScrollPane4.setViewportView(listaInternamento);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        filtroInternamentoInicioDia.setText(resourceMap.getString("filtroInternamentoInicioDia.text")); // NOI18N
        filtroInternamentoInicioDia.setName("filtroInternamentoInicioDia"); // NOI18N

        filtroInternamentoInicioMes.setText(resourceMap.getString("filtroInternamentoInicioMes.text")); // NOI18N
        filtroInternamentoInicioMes.setName("filtroInternamentoInicioMes"); // NOI18N

        filtroInternamentoInicioAno.setText(resourceMap.getString("filtroInternamentoInicioAno.text")); // NOI18N
        filtroInternamentoInicioAno.setName("filtroInternamentoInicioAno"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        filtroInternamentoFimDia.setText(resourceMap.getString("filtroInternamentoFimDia.text")); // NOI18N
        filtroInternamentoFimDia.setName("filtroInternamentoFimDia"); // NOI18N

        filtroInternamentoFimMes.setText(resourceMap.getString("filtroInternamentoFimMes.text")); // NOI18N
        filtroInternamentoFimMes.setName("filtroInternamentoFimMes"); // NOI18N

        filtroInternamentoFimAno.setText(resourceMap.getString("filtroInternamentoFimAno.text")); // NOI18N
        filtroInternamentoFimAno.setName("filtroInternamentoFimAno"); // NOI18N

        filtroInternamentoFiltrar.setAction(actionMap.get("clickedFiltrarInternamento")); // NOI18N
        filtroInternamentoFiltrar.setText(resourceMap.getString("filtroInternamentoFiltrar.text")); // NOI18N
        filtroInternamentoFiltrar.setName("filtroInternamentoFiltrar"); // NOI18N

        filtroInternamentoCancelar.setAction(actionMap.get("clickedButaoCancelarFiltroAnimais")); // NOI18N
        filtroInternamentoCancelar.setText(resourceMap.getString("filtroInternamentoCancelar.text")); // NOI18N
        filtroInternamentoCancelar.setName("filtroInternamentoCancelar"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        totalInternamentos.setText(resourceMap.getString("totalInternamentos.text")); // NOI18N
        totalInternamentos.setName("totalInternamentos"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(filtroInternamentoInicioDia, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoInicioMes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoInicioAno, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(filtroInternamentoFimDia, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoFimMes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoFimAno, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoFiltrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroInternamentoCancelar))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(novoInternamento, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(apagarInternamento))
                                    .addComponent(jLabel4)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGap(178, 178, 178)
                                        .addComponent(jLabel12)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(totalInternamentos))
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel4)
                .addGap(15, 15, 15)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel13)
                    .addComponent(filtroInternamentoInicioDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroInternamentoInicioMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroInternamentoInicioAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(filtroInternamentoFimDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroInternamentoFimMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroInternamentoFimAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroInternamentoFiltrar)
                    .addComponent(filtroInternamentoCancelar))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoInternamento)
                    .addComponent(apagarInternamento)
                    .addComponent(jLabel12)
                    .addComponent(totalInternamentos))
                .addGap(325, 325, 325))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        novoConsulta.setAction(actionMap.get("clickedNovoConsulta")); // NOI18N
        novoConsulta.setFont(resourceMap.getFont("novoConsulta.font")); // NOI18N
        novoConsulta.setForeground(resourceMap.getColor("novoConsulta.foreground")); // NOI18N
        novoConsulta.setText(resourceMap.getString("novoConsulta.text")); // NOI18N
        novoConsulta.setName("novoConsulta"); // NOI18N

        apagarConsulta.setAction(actionMap.get("clickedRemoverConsulta")); // NOI18N
        apagarConsulta.setFont(resourceMap.getFont("apagarConsulta.font")); // NOI18N
        apagarConsulta.setForeground(resourceMap.getColor("apagarConsulta.foreground")); // NOI18N
        apagarConsulta.setText(resourceMap.getString("apagarConsulta.text")); // NOI18N
        apagarConsulta.setName("apagarConsulta"); // NOI18N

        jScrollPane5.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane5.setName("jScrollPane5"); // NOI18N

        listaConsulta.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaConsulta.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaConsulta.setName("listaConsulta"); // NOI18N
        jScrollPane5.setViewportView(listaConsulta);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        filtroConsultaInicioDia.setText(resourceMap.getString("filtroConsultaInicioDia.text")); // NOI18N
        filtroConsultaInicioDia.setName("filtroConsultaInicioDia"); // NOI18N

        filtroConsultaInicioMes.setText(resourceMap.getString("filtroConsultaInicioMes.text")); // NOI18N
        filtroConsultaInicioMes.setName("filtroConsultaInicioMes"); // NOI18N

        filtroConsultaInicioAno.setText(resourceMap.getString("filtroConsultaInicioAno.text")); // NOI18N
        filtroConsultaInicioAno.setName("filtroConsultaInicioAno"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        filtroConsultaFimDia.setText(resourceMap.getString("filtroConsultaFimDia.text")); // NOI18N
        filtroConsultaFimDia.setName("filtroConsultaFimDia"); // NOI18N

        filtroConsultaFimMes.setText(resourceMap.getString("filtroConsultaFimMes.text")); // NOI18N
        filtroConsultaFimMes.setName("filtroConsultaFimMes"); // NOI18N

        filtroConsultaFimAno.setText(resourceMap.getString("filtroConsultaFimAno.text")); // NOI18N
        filtroConsultaFimAno.setName("filtroConsultaFimAno"); // NOI18N

        filtroConsultaFiltrar.setAction(actionMap.get("clickedFiltrarConsulta")); // NOI18N
        filtroConsultaFiltrar.setText(resourceMap.getString("filtroConsultaFiltrar.text")); // NOI18N
        filtroConsultaFiltrar.setName("filtroConsultaFiltrar"); // NOI18N

        filtroConsultaCancelar.setAction(actionMap.get("clickedButaoCancelarFiltroAnimais")); // NOI18N
        filtroConsultaCancelar.setText(resourceMap.getString("filtroConsultaCancelar.text")); // NOI18N
        filtroConsultaCancelar.setName("filtroConsultaCancelar"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        totalConsultas.setText(resourceMap.getString("totalConsultas.text")); // NOI18N
        totalConsultas.setName("totalConsultas"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(jLabel15)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(filtroConsultaInicioDia, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(filtroConsultaInicioMes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(filtroConsultaInicioAno, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel17))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(novoConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(apagarConsulta)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(totalConsultas)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroConsultaFimDia, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroConsultaFimMes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroConsultaFimAno, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroConsultaFiltrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtroConsultaCancelar)
                        .addGap(133, 133, 133))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 623, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(filtroConsultaInicioDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroConsultaInicioMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroConsultaInicioAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(filtroConsultaFimDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroConsultaFimMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroConsultaFimAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtroConsultaFiltrar)
                    .addComponent(filtroConsultaCancelar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoConsulta)
                    .addComponent(apagarConsulta)
                    .addComponent(jLabel18)
                    .addComponent(totalConsultas))
                .addGap(363, 363, 363))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void listaClienteValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaClienteValueChanged
        // TODO add your handling code here:
        if(listaCliente.getSelectedIndex()>=0)
            editClient(listaCliente.getSelectedIndex());
    }//GEN-LAST:event_listaClienteValueChanged

    private void listaMedicoValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaMedicoValueChanged
        // TODO add your handling code here:
        if(listaMedico.getSelectedIndex()>=0)
            showMedico(listaMedico.getSelectedIndex());
    }//GEN-LAST:event_listaMedicoValueChanged

    @Action
    public void clickedNovoMedico() {
        JFrame novaJanela = new JFrame("Novo Médico");
        newmedico newContentPane = new newmedico(novaJanela);
        newContentPane.setPai(this);
         newContentPane.setOpaque(true);
         novaJanela.setContentPane(newContentPane);

         novaJanela.pack();
         novaJanela.setVisible(true);
         novaJanela.requestFocus();
    }

    @Action
    public void clickedNovoCliente() {
        JFrame novaJanela = new JFrame("Novo Cliente");
        newcliente newContentPane = new newcliente(novaJanela);
        newContentPane.setPai(this);
         newContentPane.setOpaque(true);
         novaJanela.setContentPane(newContentPane);

         novaJanela.pack();
         novaJanela.setVisible(true);
         novaJanela.requestFocus();
    }

    @Action
    public void clickedNovoConsulta() {
        JFrame novaJanela = new JFrame("Nova Consulta");
        newconsulta newContentPane = new newconsulta(novaJanela);
        newContentPane.setPai(this);
        newContentPane.setClientes();
        newContentPane.setMedicos();
         newContentPane.setOpaque(true);
         novaJanela.setContentPane(newContentPane);

         novaJanela.pack();
         novaJanela.setVisible(true);
         novaJanela.requestFocus();
    }

    @Action
    public void clickedNovoInternamento() {
        JFrame novaJanela = new JFrame("Novo Internamento");
        newinternamento newContentPane = new newinternamento(novaJanela);
        newContentPane.setPai(this);
        newContentPane.setClientes();
        newContentPane.setMedicos();
         newContentPane.setOpaque(true);
         novaJanela.setContentPane(newContentPane);

         novaJanela.pack();
         novaJanela.setVisible(true);
         novaJanela.requestFocus();
    }

    @Action
    public void clickedNovoAnimalCliente() {
         JFrame novaJanela = new JFrame("Novo Animal");
         newbixomain newContentPane = new newbixomain(novaJanela);
         newContentPane.setPai(this);
         newContentPane.setOpaque(true);
         novaJanela.setContentPane(newContentPane);

         novaJanela.pack();
         novaJanela.setVisible(true);
         novaJanela.requestFocus();
    }

    @Action
    public void clickedGuardarCliente() {
        if (nomeCliente.getText().length()>0){
            editCliente.setNome(nomeCliente.getText());
            clinica.clientes().set(listaCliente.getSelectedIndex(), editCliente);
        }
    }

    @Action
    public void clickedRemoverCliente() {
        cancelEditClient();
        if(listaCliente.getSelectedIndex()>=0)
            this.clinica.deleteCliente(this.clinica.clientes().get(listaCliente.getSelectedIndex()));
        updateLists();
    }

    @Action
    public void clickedRemoverMedico() {
        if(listaMedico.getSelectedIndex()>=0)
            this.clinica.deleteMedico(this.clinica.medicos().get(listaMedico.getSelectedIndex()));
        updateLists();
    }

    @Action
    public void clickedRemoverInternamento() {
        if(listaInternamento.getSelectedIndex()>=0)
            this.clinica.deleteInternamento(this.clinica.internamentos().get(listaInternamento.getSelectedIndex()));
        updateLists();
    }

    @Action
    public void clickedRemoverConsulta() {
        if(listaConsulta.getSelectedIndex()>=0)
            this.clinica.deleteConsulta(this.clinica.consultas().get(listaConsulta.getSelectedIndex()));
        updateLists();
    }

    @Action
    public void clickedButaoFiltrarAnimais() {
        ArrayList<Animal> resAnimais = new ArrayList<Animal>();
        if(filtroAnimaisCliente.getSelectedIndex()==0){
            //todos clientes
            for(int i=0; i<this.clinica.clientes().size(); i++){
                Cliente tempCli = this.clinica.clientes().get(i);
                Animal[] tempAnimais;
                if(tipoFiltroAnimais.getSelectedIndex()==0){
                    //raca
                    tempAnimais = tempCli.listRaca(textoFiltro.getText());
                }else if(tipoFiltroAnimais.getSelectedIndex()==2){
                    //origem
                    tempAnimais = tempCli.listCriacaoByOrigem(textoFiltro.getText());
                }else{
                    //nome
                    tempAnimais = tempCli.listPetsByName(textoFiltro.getText());
                }
                resAnimais.addAll(Arrays.asList(tempAnimais));
            }
        }else if(filtroAnimaisCliente.getSelectedIndex()>0){
            //um cliente
            Cliente tempCli = this.clinica.clientes().get(filtroAnimaisCliente.getSelectedIndex()-1);
            Animal[] tempAnimais;
            if(tipoFiltroAnimais.getSelectedIndex()==0){
                //raca
                tempAnimais = tempCli.listRaca(textoFiltro.getText());
            }else if(tipoFiltroAnimais.getSelectedIndex()==2){
                //origem
                tempAnimais = tempCli.listCriacaoByOrigem(textoFiltro.getText());
            }else{
                //nome
                tempAnimais = tempCli.listPetsByName(textoFiltro.getText());
            }
            resAnimais.addAll(Arrays.asList(tempAnimais));
        }
        String[] resAnimaisString = new String[resAnimais.size()];
        for(int j=0; j<resAnimais.size(); j++){
            if(resAnimais.get(j).getClass()==Criacao.class)
                resAnimaisString[j] = ((Criacao)resAnimais.get(j)).listaString();
            else
                resAnimaisString[j] = ((Estimacao)resAnimais.get(j)).listaString();
        }
        listaAnimal.setListData(resAnimaisString);
    }

    @Action
    public void clickedButaoCancelarFiltroAnimais() {
        this.updateLists();
    }

    @Action
    public void clickedFiltrarInternamento() {
        //Validar as duas datas
        boolean data1Valid = true;
        String erro = "";
        int a=0, m=0, d=0;
        try{
            d = Integer.parseInt(filtroInternamentoInicioDia.getText());
            m = Integer.parseInt(filtroInternamentoInicioMes.getText());
            a = Integer.parseInt(filtroInternamentoInicioAno.getText());
        }
        catch (java.lang.NumberFormatException ne) {
            erro += "/ data de entrada inválida\r\n";
            data1Valid = false;
            a=0; m=0; a=0;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        if(d>0&&m>0&&m<=12&&a>0){

            Date testDate = null;
            try
	    {
	      testDate = dateFormat.parse(filtroInternamentoInicioDia.getText()+"/"+m+"/"+filtroInternamentoInicioAno.getText());
	    }
            catch (ParseException e)
	    {
	      erro += "/ data de entrada inválida (1)\r\n";

              data1Valid = false;
	    }

            String data = "";
            if(d<10)
                data += 0;
            data += d+"/";
            if(m<10)
                data += 0;
            data += m+"/";
            data += a;
            if (!dateFormat.format(testDate).equals(data))
	    {
	      erro += "/ "+dateFormat.format(testDate).toString()+"data de entrada inválida (2)\r\n";
	      data1Valid = false;
	    }

        }else {
            erro += "/ data de entrada inválida (3)\r\n";
	    data1Valid = false;
        }
        GregorianCalendar dataI = null;
        if(data1Valid)
            dataI = new GregorianCalendar(a,m-1,d);

        //testar segunda data
        boolean data2Valid = true;
        try{
            d = Integer.parseInt(filtroInternamentoFimDia.getText());
            m = Integer.parseInt(filtroInternamentoFimMes.getText());
            a = Integer.parseInt(filtroInternamentoFimAno.getText());
        }
        catch (java.lang.NumberFormatException ne) {
            erro += "/ data de saída inválida\r\n";
            data2Valid = false;
            a=0; m=0; a=0;
        }

        if(d>0&&m>0&&m<=12&&a>0){

            Date testDate = null;
            try
	    {
	      testDate = dateFormat.parse(filtroInternamentoFimDia.getText()+"/"+m+"/"+filtroInternamentoFimAno.getText());
	    }
            catch (ParseException e)
	    {
	      erro += "/ data de saída inválida (1)\r\n";

              data2Valid = false;
	    }

            String data = "";
            if(d<10)
                data += 0;
            data += d+"/";
            if(m<10)
                data += 0;
            data += m+"/";
            data += a;
            if (!dateFormat.format(testDate).equals(data))
	    {
	      erro += "/ "+dateFormat.format(testDate).toString()+"data de saída inválida (2)\r\n";
	      data2Valid = false;
	    }

        }else {
            erro += "/ data de saída inválida (3)\r\n";
	    data2Valid = false;
        }
        GregorianCalendar dataF = null;
        if(data2Valid){
            dataF = new GregorianCalendar(a,m-1,d);
        }

        if(data1Valid&&data2Valid)
            if(dataI.compareTo(dataF)>=0)
                dataI=null;

        Cobravel[] osInternamentos = clinica.getInternamentos(dataI, dataF);
        String[] resInternamentosString = new String[osInternamentos.length];
        for(int j=0; j<osInternamentos.length; j++){
            resInternamentosString[j] = ((Internamento)osInternamentos[j]).listaString();
        }
        listaInternamento.setListData(resInternamentosString);
        totalInternamentos.setText("€ "+clinica.getInternamentosTotal(dataI, dataF));
    }

    @Action
    public void clickedFiltrarConsulta() {
        //Validar as duas datas
        boolean data1Valid = true;
        String erro = "";
        int a=0, m=0, d=0;
        try{
            d = Integer.parseInt(filtroConsultaInicioDia.getText());
            m = Integer.parseInt(filtroConsultaInicioMes.getText());
            a = Integer.parseInt(filtroConsultaInicioAno.getText());
        }
        catch (java.lang.NumberFormatException ne) {
            erro += "/ data de entrada inválida\r\n";
            data1Valid = false;
            a=0; m=0; a=0;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        if(d>0&&m>0&&m<=12&&a>0){

            Date testDate = null;
            try
	    {
	      testDate = dateFormat.parse(filtroConsultaInicioDia.getText()+"/"+m+"/"+filtroConsultaInicioAno.getText());
	    }
            catch (ParseException e)
	    {
	      erro += "/ data de entrada inválida (1)\r\n";

              data1Valid = false;
	    }

            String data = "";
            if(d<10)
                data += 0;
            data += d+"/";
            if(m<10)
                data += 0;
            data += m+"/";
            data += a;
            if (!dateFormat.format(testDate).equals(data))
	    {
	      erro += "/ "+dateFormat.format(testDate).toString()+"data de entrada inválida (2)\r\n";
	      data1Valid = false;
	    }

        }else {
            erro += "/ data de entrada inválida (3)\r\n";
	    data1Valid = false;
        }
        GregorianCalendar dataI = null;
        if(data1Valid)
            dataI = new GregorianCalendar(a,m-1,d);

        //testar segunda data
        boolean data2Valid = true;
        try{
            d = Integer.parseInt(filtroConsultaFimDia.getText());
            m = Integer.parseInt(filtroConsultaFimMes.getText());
            a = Integer.parseInt(filtroConsultaFimAno.getText());
        }
        catch (java.lang.NumberFormatException ne) {
            erro += "/ data de saída inválida\r\n";
            data2Valid = false;
            a=0; m=0; a=0;
        }

        if(d>0&&m>0&&m<=12&&a>0){

            Date testDate = null;
            try
	    {
	      testDate = dateFormat.parse(filtroConsultaFimDia.getText()+"/"+m+"/"+filtroConsultaFimAno.getText());
	    }
            catch (ParseException e)
	    {
	      erro += "/ data de saída inválida (1)\r\n";

              data2Valid = false;
	    }

            String data = "";
            if(d<10)
                data += 0;
            data += d+"/";
            if(m<10)
                data += 0;
            data += m+"/";
            data += a;
            if (!dateFormat.format(testDate).equals(data))
	    {
	      erro += "/ "+dateFormat.format(testDate).toString()+"data de saída inválida (2)\r\n";
	      data2Valid = false;
	    }

        }else {
            erro += "/ data de saída inválida (3)\r\n";
	    data2Valid = false;
        }
        GregorianCalendar dataF = null;
        if(data2Valid){
            dataF = new GregorianCalendar(a,m-1,d);
        }

        if(data1Valid&&data2Valid)
            if(dataI.compareTo(dataF)>=0)
                dataI=null;

        Cobravel[] asConsultas = clinica.getConsultas(dataI, dataF);
        String[] resConsultasString = new String[asConsultas.length];
        for(int j=0; j<asConsultas.length; j++){
            resConsultasString[j] = ((Consulta)asConsultas[j]).listaString();
        }
        listaConsulta.setListData(resConsultasString);
        totalConsultas.setText("€ "+clinica.getConsultasTotal(dataI, dataF));
    }

    @Action
    public void clickedRemoverAnimalCliente() {
        if(listaAnimaisCliente.getSelectedIndex()>=0){
            subAnimalCliente(listaAnimaisCliente.getSelectedIndex());
            updateClientAnimalList();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton apagarAnimalCliente;
    private javax.swing.JButton apagarCliente;
    private javax.swing.JButton apagarConsulta;
    private javax.swing.JButton apagarInternamento;
    private javax.swing.JButton apagarMedico;
    private javax.swing.JButton butaoCancelarFiltroAnimais;
    private javax.swing.JButton butaoFiltrarAnimais;
    private javax.swing.JComboBox filtroAnimaisCliente;
    private javax.swing.JButton filtroConsultaCancelar;
    private javax.swing.JButton filtroConsultaFiltrar;
    private javax.swing.JTextField filtroConsultaFimAno;
    private javax.swing.JTextField filtroConsultaFimDia;
    private javax.swing.JTextField filtroConsultaFimMes;
    private javax.swing.JTextField filtroConsultaInicioAno;
    private javax.swing.JTextField filtroConsultaInicioDia;
    private javax.swing.JTextField filtroConsultaInicioMes;
    private javax.swing.JButton filtroInternamentoCancelar;
    private javax.swing.JButton filtroInternamentoFiltrar;
    private javax.swing.JTextField filtroInternamentoFimAno;
    private javax.swing.JTextField filtroInternamentoFimDia;
    private javax.swing.JTextField filtroInternamentoFimMes;
    private javax.swing.JTextField filtroInternamentoInicioAno;
    private javax.swing.JTextField filtroInternamentoInicioDia;
    private javax.swing.JTextField filtroInternamentoInicioMes;
    private javax.swing.JButton guardaCliente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JList listaAnimaisCliente;
    private javax.swing.JList listaAnimal;
    private javax.swing.JList listaCliente;
    private javax.swing.JList listaConsulta;
    private javax.swing.JList listaInternamento;
    private javax.swing.JList listaMedico;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel medicoValorMais;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextField nomeCliente;
    private javax.swing.JButton novoAnimalCliente;
    private javax.swing.JButton novoCliente;
    private javax.swing.JButton novoConsulta;
    private javax.swing.JButton novoInternamento;
    private javax.swing.JButton novoMedico;
    private javax.swing.JTextField textoFiltro;
    private javax.swing.JComboBox tipoFiltroAnimais;
    private javax.swing.JLabel totalConsultas;
    private javax.swing.JLabel totalInternamentos;
    private javax.swing.JLabel verMedicoMedia;
    private javax.swing.JLabel verMedicoNome;
    private javax.swing.JLabel verMedicoPadrao;
    private javax.swing.JPanel viewAnimalPanel;
    private javax.swing.JPanel viewClientePanel;
    private javax.swing.JPanel viewMedicoPanel;
    // End of variables declaration//GEN-END:variables



    private JDialog aboutBox;
}

class MyWindowListener implements WindowListener {

    public Clinica linkToSave;

    public MyWindowListener(Clinica clin){
        this.linkToSave = clin;
    }

  public void windowClosing(WindowEvent arg0) {
      this.linkToSave.save();
    System.exit(0);
  }

  public void windowOpened(WindowEvent arg0) {
  }

  public void windowClosed(WindowEvent arg0) {
  }

  public void windowIconified(WindowEvent arg0) {
  }

  public void windowDeiconified(WindowEvent arg0) {
  }

  public void windowActivated(WindowEvent arg0) {
  }

  public void windowDeactivated(WindowEvent arg0) {
  }

}